﻿using ExcelConfig;
using ExcelConfig.Config;
using ExcelConfig.Template;
using SanlieHash;
using System;
using System.IO;

namespace TestConsole
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(ExcelConfigSetting.CONFIG_PATH);
            ExcelConfigSetting.CONFIG_PATH = ".\\999\\test";
            Console.WriteLine(AppConfig.Text("ExcelConfigVersion"));

            AppConfig.WriteValue("asdf", "asdf");
            Console.WriteLine(AppConfig.Text("asdf"));

            var x = ExcelFile.Load("./999/app.config.xlsx", "全局");
            x.SetKeyField("12");

            var xw = x.Read(2,2).Text;

            ExcelConfigHelper.SetDefault("Test0001", "ok");
            ExcelConfigHelper.EnterPassword("Test0002", true);
            ExcelConfigHelper.Enter("Test0003");
            foreach (var line in x.ReadAllLine())
            {
                foreach (var line_key in line.Keys) 
                Console.WriteLine(line_key + ": " +line.Text(line_key));
            }
            using (var fs1 = File.Open("./999/app.config.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var cfg = new AppConfigStreamFile(fs1);
                Console.WriteLine(cfg.Text("ExcelConfigVersion"));
                Console.WriteLine(cfg.Text("ExcelConfigVersion"));
            }
            using (var cfg = new AppConfigStreamFile(AppConfig.EmptyStream()))
            {
                cfg.WriteText("test", "Test OK");
                using (var f = File.Create("3.xlsx")) cfg.ToStream(f);
            }

            using (var template = new ExcelTemplateStreamFile(File.Open("./999/app.config.xlsx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                using (var fs2 = File.Create("test.xlsx"))
                    template.TemplateOut(new { TEST = "Test OK" }, fs2);
            }
        }
    }
}
